﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.Model;
using XMK.Tadong.Data;
using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Tadong.Model.Cond;
using System.IO;
using System.Configuration;
using System.Data;

namespace XMK.Tadong.Biz
{
    public class TB_Tree_ObjectBiz
    {
        /// <summary>
        /// 查看并修改本地文件系统，使其和数据库保持一致
        /// </summary>
        /// <param name="mainPath">project 文件夹所在的绝对路径 eg(D:/project) </param>
        /// <returns></returns>
        public  bool CheckFileSystem(string mainPath)
        {
            bool resut = true;
            ResponseInfo responseInfo = QueryAllTree(0);
            List<TB_Tree_ObjectInfo> list = (List<TB_Tree_ObjectInfo>)responseInfo.Data;
           // string rootPath = Find(list, 1).ObjectName;

            List<string> dirPathList = new List<string>();
            foreach (TB_Tree_ObjectInfo info in list)
            {
                TB_Tree_ObjectInfo tmpInfo = info;
                string path="";
                while (tmpInfo.PObjectID != 0)
                {
                    path = "/" + tmpInfo.ObjectName + path;
                    tmpInfo = Find(list, tmpInfo.PObjectID); 
                }
                path = tmpInfo.ObjectName+"/"+ path;
                dirPathList.Add(path);
            }

            foreach (string path in dirPathList)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(mainPath+path);
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }
            }

            return resut;
        }

        public bool AddDir(string mainPath, string desPath, string dirName)
        {
            bool result = true;
            try
            {
                long pId = Convert.ToInt64(desPath);
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                objEditCnd.action = 3;
                objEditCnd.TypeID = 2;
                objEditCnd.IsValid = 1;
                objEditCnd.PObjectID = pId;
                objEditCnd.ObjectType = 1;
                objEditCnd.ObjectID = data.getMaxObjId(TreeType.XMK) + 1;
                objEditCnd.SN = data.getMaxObjSN((int)pId,TreeType.XMK) + 1;
                objEditCnd.ObjectName = dirName;
                //objEditCnd.


                return data.EditTreeOjbect(objEditCnd);


                /*
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                desPath = desPath.TrimEnd();
                desPath = desPath.EndsWith("/") ? desPath.Substring(0, desPath.Length - 1) : desPath;
                string subPath = desPath.Split('/').Last();
                DirectoryInfo desInfo = new DirectoryInfo(desPath);

                DirectoryInfo mainPathInfo = new DirectoryInfo(mainPath);
                int lenDes = desInfo.FullName.Length;
                int lenMain = mainPathInfo.FullName.Length;
                string tmpDes = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, lenDes - 1) : desInfo.FullName;
                string tmpMain = mainPathInfo.FullName.EndsWith("\\") ? mainPathInfo.FullName.Substring(0, lenMain - 1) : mainPathInfo.FullName;

                if (tmpDes == tmpMain)
                {
                     int pId = 0;
                    TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                    objEditCnd.action = 3;
                    objEditCnd.TypeID = 2;
                    objEditCnd.IsValid = 1;
                    objEditCnd.PObjectID = pId;
                    objEditCnd.ObjectType = 1;
                    objEditCnd.ObjectID = data.getMaxObjId() + 1;
                    objEditCnd.SN = data.getMaxObjSN(pId) + 1;
                    objEditCnd.ObjectName = dirName;
                    //objEditCnd.
                    data.EditTreeOjbect(objEditCnd);

                    return true;
                }


                ResponseInfo responseInfo = QueryAllTree(0);
                List<TB_Tree_ObjectInfo> list = (List<TB_Tree_ObjectInfo>)responseInfo.Data;
                int id = 0;
                foreach (TB_Tree_ObjectInfo info in list)
                {
                    TB_Tree_ObjectInfo tmpInfo = info;
                    string path = "";
                    while (tmpInfo.PObjectID != 0)
                    {
                        path = "/" + tmpInfo.ObjectName + path;
                        tmpInfo = Find(list, tmpInfo.PObjectID);
                    }
                    path = tmpInfo.ObjectName + "/" + path;
                    if (path.EndsWith(subPath) || path.EndsWith(subPath + "/"))
                    {
                        DirectoryInfo info1 = new DirectoryInfo(mainPath + path);
                        int len = info1.FullName.Length;
                        string path1 = info1.FullName.EndsWith("\\") ? info1.FullName.Substring(0, len - 1) : info1.FullName;
                        len = desInfo.FullName.Length;
                        string path2 = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, len - 1) : desInfo.FullName;
                        if (path1 == path2)
                        {
                            id = info.ObjectID;
                            TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                            objEditCnd.action = 3;
                            objEditCnd.TypeID = 0;
                            objEditCnd.IsValid = 1;
                            objEditCnd.PObjectID = id;
                            objEditCnd.ObjectType = info.ObjectType+1;
                            objEditCnd.ObjectID = data.getMaxObjId() + 1;
                            objEditCnd.SN = data.getMaxObjSN(id) + 1;
                            objEditCnd.ObjectName = dirName;
                            //objEditCnd.
                            data.EditTreeOjbect(objEditCnd);
                            //EditTreeOjbect(
                            break;
                        }
                    }
                }
                */
            }
            catch (Exception ex)
            {
                string info = ex.Message;
                result = false;
            }

            return result;
        }

        public bool Delete(string mainPath, string desPath)
        {
            bool result = true;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                desPath = desPath.TrimEnd();
                desPath = desPath.EndsWith("/") ? desPath.Substring(0, desPath.Length - 1) : desPath;
                string subPath = desPath.Split('/').Last();
                DirectoryInfo desInfo = new DirectoryInfo(desPath);

                DirectoryInfo mainPathInfo = new DirectoryInfo(mainPath);
                int lenDes = desInfo.FullName.Length;
                int lenMain = mainPathInfo.FullName.Length;
                string tmpDes = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, lenDes - 1) : desInfo.FullName;
                string tmpMain = mainPathInfo.FullName.EndsWith("\\") ? mainPathInfo.FullName.Substring(0, lenMain - 1) : mainPathInfo.FullName;

                //if (tmpDes == tmpMain)
                //{
                //    int pId = 0;
                //    TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                //    objEditCnd.action = 3;
                //    objEditCnd.TypeID = 0;
                //    objEditCnd.IsValid = 1;
                //    objEditCnd.PObjectID = pId;
                //    objEditCnd.ObjectType = 1;
                //    objEditCnd.ObjectID = data.getMaxObjId() + 1;
                //    objEditCnd.SN = data.getMaxObjSN(pId) + 1;
                //    objEditCnd.ObjectName = dirName;
                //    //objEditCnd.
                //    data.EditTreeOjbect(objEditCnd);

                //    return true;
                //}


                ResponseInfo responseInfo = QueryAllTree(0);
                List<TB_Tree_ObjectInfo> list = (List<TB_Tree_ObjectInfo>)responseInfo.Data;
                int id = 0;
                foreach (TB_Tree_ObjectInfo info in list)
                {
                    TB_Tree_ObjectInfo tmpInfo = info;
                    string path = "";
                    while (tmpInfo.PObjectID != 0)
                    {
                        path = "/" + tmpInfo.ObjectName + path;
                        tmpInfo = Find(list, tmpInfo.PObjectID);
                    }
                    path = tmpInfo.ObjectName + "/" + path;
                    if (path.EndsWith(subPath) || path.EndsWith(subPath + "/"))
                    {
                        DirectoryInfo info1 = new DirectoryInfo(mainPath + path);
                        int len = info1.FullName.Length;
                        string path1 = info1.FullName.EndsWith("\\") ? info1.FullName.Substring(0, len - 1) : info1.FullName;
                        len = desInfo.FullName.Length;
                        string path2 = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, len - 1) : desInfo.FullName;
                        if (path1 == path2)
                        {
                            id = info.ObjectID;
                            TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                            objEditCnd.action = 0;//delete 
                            objEditCnd.TypeID = 0;
                            objEditCnd.IsValid = 1;
                            objEditCnd.ObjectID = id;
                            //objEditCnd.ObjectType = info.ObjectType + 1;
                            //objEditCnd.ObjectID = data.getMaxObjId() + 1;
                            //objEditCnd.SN = data.getMaxObjSN(id) + 1;
                            //objEditCnd.ObjectName = dirName;
                            //objEditCnd.

                            try
                            {
                               bool result1=data.EditTreeOjbect(objEditCnd);
                            }
                            catch (Exception ex)
                            {
                                string str = ex.Message;
                            }
                            //EditTreeOjbect(
                            break;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                string info = ex.Message;
            }

            return result;
        }

        public bool Rename(string mainPath, string desPath,string newName)
        {
            bool result = true;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                desPath = desPath.TrimEnd();
                desPath = desPath.EndsWith("/") ? desPath.Substring(0, desPath.Length - 1) : desPath;
                string subPath = desPath.Split('/').Last();
                DirectoryInfo desInfo = new DirectoryInfo(desPath);

                DirectoryInfo mainPathInfo = new DirectoryInfo(mainPath);
                int lenDes = desInfo.FullName.Length;
                int lenMain = mainPathInfo.FullName.Length;
                string tmpDes = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, lenDes - 1) : desInfo.FullName;
                string tmpMain = mainPathInfo.FullName.EndsWith("\\") ? mainPathInfo.FullName.Substring(0, lenMain - 1) : mainPathInfo.FullName;
                ResponseInfo responseInfo = QueryAllTree(0);
                List<TB_Tree_ObjectInfo> list = (List<TB_Tree_ObjectInfo>)responseInfo.Data;
                int id = 0;
                foreach (TB_Tree_ObjectInfo info in list)
                {
                    TB_Tree_ObjectInfo tmpInfo = info;
                    string path = "";
                    while (tmpInfo.PObjectID != 0)
                    {
                        path = "/" + tmpInfo.ObjectName + path;
                        tmpInfo = Find(list, tmpInfo.PObjectID);
                    }
                    path = tmpInfo.ObjectName + "/" + path;
                    if (path.EndsWith(subPath) || path.EndsWith(subPath + "/"))
                    {
                        DirectoryInfo info1 = new DirectoryInfo(mainPath + path);
                        int len = info1.FullName.Length;
                        string path1 = info1.FullName.EndsWith("\\") ? info1.FullName.Substring(0, len - 1) : info1.FullName;
                        len = desInfo.FullName.Length;
                        string path2 = desInfo.FullName.EndsWith("\\") ? desInfo.FullName.Substring(0, len - 1) : desInfo.FullName;
                        if (path1 == path2)
                        {
                            id = info.ObjectID;
                            TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                            objEditCnd.action = 4;//Rename
                            objEditCnd.TypeID = 0;
                            objEditCnd.ObjectID = id;
                            objEditCnd.ObjectName = newName;
                            try
                            {
                                bool result1 = data.EditTreeOjbect(objEditCnd);
                            }
                            catch (Exception ex)
                            {
                                string str = ex.Message;
                            }
                            //EditTreeOjbect(
                            break;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                string info = ex.Message;
            }

            return result;
        }

        

        public List<TB_Tree_ObjectInfo> GetChildById(int id,TreeType treeType = TreeType.Target)
        {
              TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
              List<TB_Tree_ObjectInfo> list = data.QueryChildObjectById(id, treeType); 

              return list;
        }

        /// <summary>
        /// 通过关键词查询目标树或业务树数据
        /// </summary>
        /// <param name="treeType"></param>
        /// <returns></returns>
        public List<TB_Tree_ObjectInfo> QueryChildObjectByIdAndKeyWord(int id, string keyword, TreeType treeType = TreeType.Target)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            List<TB_Tree_ObjectInfo> list = data.QueryChildObjectByIdAndKeyWord(id, keyword, treeType);

            return list;
        }

        /// <summary>
        /// 通过关键词查询目标树或业务树数据
        /// </summary>
        /// <param name="id">文件夹ID</param>
        /// <param name="personID">用户ID</param>
        /// <param name="TEAM_ID">课题组ID</param>
        /// <param name="treeType">查询类型</param>
        /// <param name="keyword">关键词</param>
        /// <returns></returns>
        public List<TB_Tree_ObjectInfo> PTQueryChildObjectByIdAndKeyWord(int id, string personID, string TEAM_ID, string treeType, string keyword)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            List<TB_Tree_ObjectInfo> list = data.PTQueryChildObjectByIdAndKeyWord(id, personID, TEAM_ID, treeType,keyword);
            return list;
        }

        /// <summary>
        /// 查询目标树或业务树数据
        /// </summary>
        /// <param name="treeType"></param>
        /// <returns></returns>
        public List<TB_Tree_ObjectInfo> QueryChildObjectById(int id,string PersonID,string Team_ID ,string treeType)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            List<TB_Tree_ObjectInfo> list = data.PTQueryChildObjectById(id, PersonID, Team_ID, treeType);

            return list;
        }

        public int  GetChildCountById(int id, TreeType treeType = TreeType.XMK)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return   data.QueryChildObjectById(id, treeType).Count;

          
        }

        public int GetChildCountByIdAndKeyWord(int id, string keyword, TreeType treeType = TreeType.XMK)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.QueryChildObjectByIdAndKeyWord(id,keyword, treeType).Count;


        }

        public int GetChildCountById1(int id, string PersonID, string Team_ID, string treeType)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.PTQueryChildObjectById(id, PersonID, Team_ID, treeType).Count;
        }

        public int GetChildCountByIdAndKeyWord1(int id, string PersonID, string Team_ID, string treeType,string keyword)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.PTQueryChildObjectByIdAndKeyWord(id, PersonID, Team_ID, treeType, keyword).Count;
        }

        private TB_Tree_ObjectInfo Find( List<TB_Tree_ObjectInfo> list,int id)
        {
            TB_Tree_ObjectInfo info = new TB_Tree_ObjectInfo();
            foreach (TB_Tree_ObjectInfo info_ in list)
            {
                if (info_.ObjectID == id)
                {
                    info = info_;
                    break;
                }
            }

            return info;
        }


        /// <summary>
        /// 0:目标树,1:业务树,2：项目库
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryAllTree(int typeId)
        {
            ResponseInfo response = null;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<TB_Tree_ObjectInfo>)data.QueryAllTreeObject((TreeType)typeId);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryAllTree:]" + ex.ToString());
            }
            return response;
        }

        /// <summary>
        /// 0:目标树,1:业务树,2：项目库
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryTreeByPID(int P_OBJ_ID)
        {
            ResponseInfo response = null;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<TB_Tree_ObjectInfo>)data.QueryTreeObjectByPID1(P_OBJ_ID,0);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryAllTree:]" + ex.ToString());
            }
            return response;
        }

        public ResponseInfo GetTreeInfoByID(TB_Tree_ObjectCond cond)
        {
            ResponseInfo response = null;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (TB_Tree_ObjectInfo)data.GetTreeInfoByID(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("调用数据error！");
                LogHelper.WriteLog(LogType.Error, "[GetTreeInfoByID:]" + ex.ToString());
            }
            return response;
        }


        public ResponseInfo EditTreeOjbect(TB_TreeObjectEditCond cond)
        {
            ResponseInfo response = null;
            try
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = data.EditTreeOjbect(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditTreeOjbect:]" + ex.ToString());
            }
            return response;
        }
        
       /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetTree_Person(string OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetTree_PersonBySql(OBJ_ID);
        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetTree_Team(string OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetTree_TeamBySql(OBJ_ID);
        }

        /// <summary>
        /// 文件夹重命名
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool PersonlRename(TB_Tree_ObjectInfo model)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.Rename(model, "person");
        }

        /// <summary>
        /// 文件夹重命名
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool TeamRename(TB_Tree_ObjectInfo model)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.Rename(model, "team");
        }

        /// <summary>
        /// 项目库文件夹剪切
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,error返回false</returns>
        public bool UpdateTree_PersonCUT(TB_Tree_ObjectInfo model)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.UpdateTree_PersonCUTBySql(model);
        }

        /// <summary>
        /// 项目库文件夹剪切
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,error返回false</returns>
        public bool UpdateTree_TeamCUT(TB_Tree_ObjectInfo model)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.UpdateTree_TeamCUTBySql(model);
        }

         /// <summary>
        /// 获取子文件夹文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetTree_PersonP_ID(string OBJ_ID)
        {
             TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
             return data.GetTree_PersonByP_ID(OBJ_ID);
        }

        /// <summary>
        /// 获取子文件夹文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetTree_TeamP_ID(string OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetTree_TeamByP_ID(OBJ_ID);
        }

        //删除文件夹
        public bool deleteTREE_PersonBySQL(string OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.deleteTREE_PersonBySQL(OBJ_ID);
        }

        //删除文件夹
        public bool deleteTREE_TeamBySQL(string OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.deleteTREE_TeamBySQL(OBJ_ID);
        }

        //个人空间新建文件夹
        public bool PersonAddDir(string mainPath, string desPath, string dirName,string User_id)
        {
            bool result = true;
            try
            {
                long pId = Convert.ToInt64(desPath);
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                objEditCnd.action = 3;
                objEditCnd.TypeID = 2;
                objEditCnd.IsValid = 1;
                objEditCnd.PObjectID = pId;
                objEditCnd.ObjectType = 1;
                objEditCnd.ObjectID = data.getMaxObjId(TreeType.PERSON) + 1;
                objEditCnd.SN = data.getMaxObjSN((int)pId, TreeType.PERSON) + 1;
                objEditCnd.ObjectName = dirName;
                objEditCnd.USER_ID = User_id;
                //objEditCnd.


                return data.PersonAddDir(objEditCnd);

            }
            catch (Exception ex)
            {
                string info = ex.Message;
                result = false;
            }

            return result;
        }

        //课题组空间新建文件夹
        public bool TeamAddDir(string mainPath, string desPath, string dirName, string User_id,string Team_ID)
        {
            bool result = true;
            try
            {
                long pId = Convert.ToInt64(desPath);
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                TB_TreeObjectEditCond objEditCnd = new TB_TreeObjectEditCond();
                objEditCnd.action = 3;
                objEditCnd.TypeID = 2;
                objEditCnd.IsValid = 1;
                objEditCnd.PObjectID = pId;
                objEditCnd.ObjectType = 1;
                objEditCnd.ObjectID = data.getMaxObjId(TreeType.TEAM) + 1;
                objEditCnd.SN = data.getMaxObjSN((int)pId, TreeType.TEAM) + 1;
                objEditCnd.ObjectName = dirName;
                objEditCnd.USER_ID = User_id;
                objEditCnd.Team_ID = Team_ID;

                //objEditCnd.


                return data.TeamAddDir(objEditCnd);

            }
            catch (Exception ex)
            {
                string info = ex.Message;
                result = false;
            }

            return result;
        }
        /// <summary>
        /// 获取目标树的第一级
        /// </summary>
        /// <returns>目标树列表</returns>
        public DataTable GetTreeTargetOne()
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetTreeTargetOne();
        }

        /// <summary>
        /// 获取通过父级ID目标树的子级
        /// </summary>
        /// <returns>目标树列表</returns>
        public DataTable GetSubTreeTarget(string P_OBJ_ID)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetSubTreeTarget(P_OBJ_ID);
        }

        public DataTable GetNodeById(string obj_id)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetTargetNode(obj_id);
        }

        public DataTable QuerySql(string sql)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.QuerySql(sql);
        }



        public DataTable GetAllSubTreeTarget(string id)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetAllSubTreeTarget(id);
        }
        public DataTable getSearchTarget(string target, string bus)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.getSearchTarget(target, bus);
        }


        public DataTable getTableData(string tableName, string target)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.getTableData(tableName, target);
        }

        public DataTable getSearchBiz(string target, string biz)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            string strSql = " select * from tb_xmk_file where '" + target + "'in  (select * from table(splitstr(dest_obj,' ')) ) and  '" + biz + "' in  (select * from table(splitstr(biz_obj,' ')) ) ";
            return data.QuerySql(strSql);
        }

        public DataTable getSearchBiz1(string target, string biz)
        {
            //目标业务都为空
            if ((biz == "其他" || biz == "Other") && (target == "其他" || target == "Other"))
            {
              
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                string strSql = " select * from tb_xmk_file where dest_obj is null and  biz_obj is null ";
                return data.QuerySql(strSql);
                
            }
            //业务为空，目标不为空
            else if ((biz == "其他" || biz == "Other"))
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                string strSql = " select * from tb_xmk_file where '" + target + "'in  (select * from table(splitstr(dest_obj,' ')) ) and  biz_obj is null ";
                return data.QuerySql(strSql);
            }
            //目标为空，业务不为空
            else if (target == "其他" || target == "Other")
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                string strSql = " select * from tb_xmk_file where dest_obj is null and  '" + biz + "' in  (select * from table(splitstr(biz_obj,' ')) ) ";
                return data.QuerySql(strSql);
            }
            //目标业务都不为空
            else
            {
                TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
                string strSql = " select * from tb_xmk_file where '" + target + "'in  (select * from table(splitstr(dest_obj,' ')) ) and  '" + biz + "' in  (select * from table(splitstr(biz_obj,' ')) ) ";
                return data.QuerySql(strSql);
            }
           
        }

        public DataTable getGridData(string id)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.QueryGridData(id);
        }
        public DataTable getBizNames()
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.QueryBus();
        }
        public DataTable getBisData(string parentId)
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.QueryBusData(parentId);

        }

        public DataTable GetAllTreeTarget()
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetAllTreeTarget();

        }
        public DataTable GetAllTreeBiz()
        {
            TB_Tree_ObjectData data = new TB_Tree_ObjectData(Config.TadongDbProvider);
            return data.GetAllTreeBiz();

        }
        



    }
}
